package com.hejl.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.QuestionAnswerAdvisor;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Hejl
 * @version 1.0
 * @description
 * @className SpringAiRagController
 * @date 2025/6/11 10:06
 */
@RestController
public class SpringAiRagController {
    @Autowired
    private ChatClient chatClient;
    @Autowired
    private VectorStore vectorStore;

    @GetMapping("/rag")
    public String rag(String question) {
        String result = chatClient.prompt()
                .user(question)
                .advisors(new QuestionAnswerAdvisor(vectorStore))//添加向量数据库
                .call()
                .content();
        return result;
    }
}